/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package assignment_cp3120.ucm;

import assignment_cp3120.administrator.deletemanager.DeleteManagerModel;
import assignment_cp3120.administrator.deletemanager.DeleteManagerView;
import assignment_cp3120.user.UserView;

/**
 *  DELETE USER USE-CASE
 * 
 * Precondition: System shows the delete manager view
 *<P>
 *  1. User enters username
 *  2. User clicks delete
 *  3. System validates username
 *  4. System checks that username is a manager
 *  5. System deletes from database
 * 
 *  3.a.1 System detects that the username does not exist in database
 *  3.a.2  System shows error dialog
 *  3.a.3 System clears username and password fields 
 *<P>
 *  Postcondition: Manager delete view is closed
 * @author Richard
 */
public class UCDeleteManager implements UseCaseController{
    
    private DeleteManagerModel model;
    private DeleteManagerView view;
    /**
     * Defualt constructor, calls Constructor(model,view) with new model and new view
     */
    public UCDeleteManager(){
        this(new DeleteManagerModel(), DeleteManagerView.getInstance());
    }
    /**
     * Constructor that sets the model, view and frame to the input valus and sets the buttonlisteners
     * @param model
     * Set this.model to the input
     * @param view
     * Set this.view to the input
     */
    public UCDeleteManager(DeleteManagerModel model, DeleteManagerView view) {
        this.model = model;
        this.view = view;
    }
    public void run() {
        //3. System validates username
        if(model.validate(view.getUsernameField())){
            //4. System checks that username is a manager
            if (model.managerIsManager()){
            //5. System deletes from database 
            model.deleteUser();
            view.successMessageBox();
            view.hideGUI();
            }
            //4.a.1 System detects that the user is not a user
            else {                
                //4.a.2 System shows error dialog
                view.notManagerMessageBox();
                //4.a.3 System hides the password verification screen)
                view.hideGUI();
            }
        }
        //3.a.1 System detects that the username does not exist in database
        else {
            //3.2 System shows error dialog
            view.usernameErrorMessageBox();
            //3.a.3 System clears username and password fields 
            view.clearUsernameField();
        }
    }
    
    
}
